package com.bcx.service.impl;

import com.bcx.mapper.AirMapper;
import com.bcx.pojo.Air;
import com.bcx.pojo.AirExample;
import com.bcx.service.AirService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class AirServiceImpl implements AirService {
    @Resource
    AirMapper airMapper;
    @Override
    public PageInfo<Air> selectAll(Integer districtid, Integer pageNum) {
        PageHelper.startPage(pageNum,2);
        List<Air> airList;
        AirExample example=new AirExample();
        if (districtid!=0){
            AirExample.Criteria criteria= example.createCriteria();
            criteria.andDistrictidEqualTo(districtid);
            airList=airMapper.selectByExample(example);
        }else {
            airList=airMapper.selectByExample(null);
        }
        PageInfo<Air> pageInfo=new PageInfo<>(airList);
        return pageInfo;
    }

    @Override
    public Integer insert(Air air) {
        return airMapper.insert(air);
    }

    @Override
    public Integer delete(Integer id) {
        return airMapper.deleteByPrimaryKey(id);
    }

    @Override
    public Air getById(Integer id) {
        return airMapper.selectByPrimaryKey(id);
    }

    @Override
    public Integer update(Air air) {
        return airMapper.updateByPrimaryKeySelective(air);
    }
}
